import { _decorator, Component, Node, sys } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('toolsScript')
export class toolsScript extends Component {
    // 跨平台存储
    static setItem(key: string, value: string) {

      if (typeof wx !== 'undefined') {
        console.log(" Here 1");
        wx.setStorageSync(key, value); // 微信同步接口
      } else {
        console.log(" Here 2");
        sys.localStorage.setItem(key, value);
      }
    }

    // 跨平台读取
    static getItem(key: string): string {
      if (typeof wx !== 'undefined') {
        try {
            console.log(" Here 3");
          return wx.getStorageSync(key);
        } catch {
            console.log(" Here 4");
          return null;
        }
      } else {
        console.log(" Here 5");
        return sys.localStorage.getItem(key) || '';
      }
    }
}


